package com.example.game1;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;

import com.example.game1.managers.GridManager;
import com.example.game1.rooms.Level1;
import com.example.game1.views.DrawingSurface;



public class MainActivity extends Activity implements SurfaceHolder.Callback, OnTouchListener
{
	
	// The surface that will do the drawing to the screen
	public DrawingSurface mDrawingSurface;
	public Handler mThreadHandler;
	public GridManager mGridManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{

		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
		setContentView(R.layout.drawing_surface_layout);
		
		mDrawingSurface = (DrawingSurface) findViewById(R.id.drawing_surface);
		mDrawingSurface.getHolder().addCallback(this);
		
		mDrawingSurface.setOnTouchListener(this);
		
		// Initialize the GridManager
		GridManager.init(this, mDrawingSurface.getWidth(), mDrawingSurface.getHeight());
		mGridManager = GridManager.getInstance();
		
		// Set the current room for the GridManager
		mGridManager.setRoom(new Level1(this));
		
		// Initialize the GameLoop
		GameLoop.init(this);
		
		
	}

	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) 
	{

		
	}

	public void surfaceCreated(SurfaceHolder arg0) 
	{
		// We are ready to start
		GameLoop.getInstance().startGameLoop();
		
	}

	public void surfaceDestroyed(SurfaceHolder arg0) 
	{
		GameLoop.getInstance().stopGameLoop();
	}

	public boolean onTouch(View v, MotionEvent event) 
	{
		float mWaypointX = event.getX();
		float mWaypointY = event.getY();
		mGridManager.convertPixelsToGrid(mWaypointX,mWaypointY);
		return true;
	}

}
